package ch.usi.inf.pf2.editor;

import java.awt.Color;

import javax.swing.border.Border;

import ch.usi.inf.pf2.Sheet;

/**
 * This is a sort of container for the actions cut, copy and paste
 * 
 * @author Lorenzo Baracchi, Ebrisa Savina Mastrodicasa
 *
 */
public abstract class TextManagement extends Action
{
	private String oldText;
	private String newText;
	
	private Color oldColor;
	private Color newColor;
	
	private Border oldBorder;
	private Border newBorder;
	
	
	/**
	 * Constructor used for TextManagement
	 * @param sheet
	 * @param rowIndex the row index
	 * @param columnIndex the column index
	 */
	protected TextManagement (Sheet sheet, int rowIndex, int columnIndex)
	{
		super(sheet, rowIndex, columnIndex);
	}
	
	protected TextManagement ()
	{
	    
	}
	
	/**
	 * Compare two objects and return true if their contents are the same.
	 */
	public boolean equals (Object o)
	{
		if(o instanceof TextManagement)
			return (oldText.equals(((TextManagement)o).oldText) && newText.equals(((TextManagement)o).newText) &&
					oldColor.equals(((TextManagement) o).oldColor) && newColor.equals(((TextManagement) o).newColor) &&
					oldBorder.equals(((TextManagement) o).oldBorder) && oldBorder.equals(((TextManagement) o).newBorder));
		else
			return false;
	}
	
	/**
	 * @return The text before any change.
	 */
	public String getOldText()
	{
		return oldText;
	}
	
	
	/**
	 * @return The text after some change.
	 */
	public String getNewText()
	{
		return newText;
	}	
	
	
	/**
	 * Set the old text field at a given text.
	 * @param oldText The text to be set.
	 */
	void setOldText(String oldText)
	{
		this.oldText = oldText;
	}
		
	
	/**
	 * Set the new text field at a given text.
	 * @param newText the text to be set.
	 */
	void setNewText(String newText)
	{
		this.newText = newText;
	}
	
	
	/**
	 * @return The color before any change.
	 */
	Color getOldColor()
	{
		return oldColor;
	}
	
	
	/**
	 * @return The color after some change.
	 */
	Color getNewColor()
	{
		return newColor;
	}
	
	
	/**
	 * Set the old color field at a given color.
	 * @param oldColor The old color to be set
	 */
	void setOldColor(Color oldColor)
	{
		this.oldColor = oldColor;
	}
	
	
	/**
	 * Set the new color field at a given color.
	 * @param newColor The new color to be set
	 */
	void setNewColor(Color newColor)
	{
		this.newColor = newColor;
	}
	
	
	/**
	 * @return The border before any change
	 */
	Border getOldBorder()
	{
		return oldBorder;
	}
	
	
	/**
	 * @return The border after some change
	 */
	Border getNewBorder()
	{
		return newBorder;
	}
	
	
	/**
	 * Set the old border at a given border.
	 * @param oldBorder The old border to be set.
	 */
	void setOldBorder(Border oldBorder)
	{
		this.oldBorder = oldBorder;
	}
	
	
	/**
	 * Set the new border at a given border.
	 * @param newBorder The new border to be set.
	 */
	void setNewBorder(Border newBorder)
	{
		this.newBorder = newBorder;
	}
	
	
	/**
	 * Evaluate the action
	 */
	public abstract void evaluate ();
	
	
	/**
	 * Restore the values as they where before the evaluate()
	 */
	public abstract void restore();
}
